package com.admission.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import com.admission.dao.MajorDao;
import com.admission.model.Major;

@Repository
@Transactional
public class MajorManager {
	private MajorDao majorDao;
    private AcademyManager academyManager;
    
    @Autowired
  	public void setMajorDao(MajorDao majorDao) {
  		this.majorDao = majorDao;
  	}
      @Autowired
  	public void setAcademyManager(AcademyManager academyManager) {
  		this.academyManager = academyManager;
  	}
      
      /**
  	 * 通过id找唯一对象，无返回null
  	 * 
  	 * @param id
  	 * @return Major
  	 */
  	public Major getMajorById(String id) {
  		return majorDao.findUniqueBy("id", id);
  	}
	/**
	 * 保存
	 * 
	 * @param Entity
	 * @return null
	 */
	public void save(Major entity,String id) throws Exception{
		 entity.setAcademy(academyManager.getAcademyById(id));
		 majorDao.save(entity);
	}
	 
	/**
	 * 通过filter分页查询结果
	 * 
	 * @param page
	 * @param filters
	 * @return  Page<Major>
	 */
	public Page<Major> getPageByFilter(Page<Major> page,
			List<PropertyFilter> filters) {
		return majorDao.findPage(page, filters);
	}
	/**
	 * 通过filter查询结果
	 * 
	 * @param filters
	 * @return List<Major>
	 */
	public List<Major> getListByFilter(List<PropertyFilter> filters) {
		return majorDao.find(filters);
	}
	/**
	 * 删除
	 * 
	 * @param Entity
	 * @return null
	 */
	public void delete(String id) throws Exception{
		 majorDao.delete(id);
	}
	/**
	 * 批量删除
	 * 
	 * @param Entity
	 * @return null
	 */
	public void deleteMore(String ids) throws Exception{
		for(String id : ids.split(",")){
			majorDao.delete(id.trim());
		}
	}
	
}
